package com.itheima.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Aspect
public class ServiceFindAop {

    @Pointcut("execution(* com.itheima.service.*.*(..))")
    public void pt(){}

    @Pointcut("execution(* com.itheima.service.*.select*(..))")
    public void pt1(){}

    /*@Before("pt()")
    public void Before(){
        System.out.println("Before 在方法执行之前执行");
    }

    @Before("pt1()")
    public void method1(){
        System.out.println(LocalDateTime.now());
    }

    @After("pt()")
    public void after(){
        System.out.println("after 在方法执行之后执行");
    }

    @AfterReturning("pt()")
    public void afterReturn(){
        System.out.println("afterReturn 在方法执行完return后执行");
    }


    @AfterThrowing("pt()")
    public void afterThrow(){
        System.out.println("afterThrow 在方法报错后执行");
    }*/

    /*@Around("pt()")
    public Object around(ProceedingJoinPoint pjp){
        System.out.println("前置....");
        Object proceed = null;
        try {
            proceed = pjp.proceed();
            System.out.println("后置....");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("异常....");
        }finally {
            System.out.println("最终....");
        }

        return proceed;
    }*/

    @Around("pt()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        Object proceed = pjp.proceed();
        long end = System.currentTimeMillis();

        System.out.println("运行所要时间:"+(end-start));

        return proceed;
    }
}
